package com.test38_集合;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

/**
 * Properties类
 */
public class Demo08_Properties {

    @Test
    public void test1() {
        Properties properties = new Properties();
        properties.setProperty("YOOTK", "沐言优拓：www.yootk.com");
        properties.setProperty("EDU", "VIP大纲：edu.yootk.com");
        properties.setProperty("VIP", "VIP直播课堂：yootk.ke.qq.com");
        // System.out.println(properties);
        System.out.println("【获取属性KEY存在】" + properties.getProperty("YOOTK"));
        System.out.println("【获取属性KEY不存在】" + properties.getProperty("MUYAN"));
        System.out.println("【获取属性KEY不存在】" + properties.getProperty("MUYAN", "暂未启用"));
    }

    /**
     * 通过Properties保存属性文件
     */
    @Test
    public void test2() throws Exception {
        Properties properties = new Properties();
        properties.setProperty("YOOTK", "沐言优拓：www.yootk.com");
        properties.setProperty("EDU", "VIP大纲：edu.yootk.com");
        properties.setProperty("VIP", "VIP直播课堂：yootk.ke.qq.com");
        properties.store(new FileOutputStream(new File("F:" + File.separator + "muyan" + File.separator + "MuYan.properties")),
                "MuYanInfo");
    }

    /**
     * 通过文件读取属性内容
     */
    @Test
    public void test3() throws Exception {
        Properties properties = new Properties();
        properties.load(new FileInputStream(new File("F:" + File.separator + "muyan" + File.separator + "MuYan.properties")));
        System.out.println("【获取属性信息】" + properties.getProperty("YOOTK"));
        System.out.println("【获取属性信息】" + properties.getProperty("EDU"));
        System.out.println("【获取属性信息】" + properties.getProperty("VIP"));
    }
}
